let index = 0;
const slides = document.querySelectorAll('.swiper-image');
const dots = document.querySelectorAll('.swiper-dots');
const totalSlides = slides.length;

//更新活动点的函数
function updateDots() {
  document.querySelectorAll('.swiper-dot').forEach(dot => dot.classList.remove('active'));
  document.querySelectorAll('.swiper-dot')[index].classList.add('active');
}

// 移动到特定幻灯片的函数
function moveSlide(step) {
  index = (index + step + totalSlides) % totalSlides;
  
  slides.forEach((slide, i) => {
    slide.style.display = i === index ? 'block' : 'none';
  });
  updateDots();
}

// 初始化点
slides.forEach((slide, i) => {
  const dot = document.createElement('div');
  dot.classList.add('swiper-dot');
  if (i === 0) dot.classList.add('active');
  dots[0].appendChild(dot);
});

// 点击的事件侦听器
document.querySelectorAll('.swiper-dot').forEach((dot, i) => {
  dot.addEventListener('click', () => {
    moveSlide(i - index);
  });
});

// 自动换幻灯片
setInterval(() => {
  moveSlide(1);
}, 3000); // 每3秒更改一次图像